Check if attribute exists if so bring back parent object information

Hi, I'm trying to check if a linked module has a certain attribute (Release Number) and if it does then go into the linked object, then go up one level to the Parent object and bring back information in the Release Number attribute.

After plenty of attempts to get it to work I've succeeded, somewhat, except it brings back way more information than there are links (e.g. 5 links brings back 45 results). Can anyone help me remove the duplicates please?
 

// DXL generated by DOORS traceability wizard on 09 March 2012.
// Wizard version 2.0, DOORS version 9.3.0.5
pragma runLim, 0
string limitModules[1] = {"48c520b3464303c3-0000b4ad"}
void showIn(Object o, int depth) {
    Link l
    LinkRef lr
    ModName_ otherMod = null
    Module linkMod = null
    ModuleVersion otherVersion = null
    Object othero
    Object PO
    string disp = null
    string s = null
    string plain, plainDisp
    int plainTextLen
    int count
    bool doneOne = false
    string linkModName = "*"
    for lr in all(o<-linkModName) do {
        otherMod = module (sourceVersion lr)
        if (!null otherMod) {
            if ((!isDeleted otherMod) && (null data(sourceVersion lr))) {
                if (!equal(getItem otherMod, (itemFromID limitModules[depth-1]))) continue
                load((sourceVersion lr),false)
            }
        }
    }
    for l in all(o<-linkModName) do {
        otherVersion = sourceVersion l
        otherMod = module(otherVersion)
        if (null otherMod || isDeleted otherMod) continue
        if (!equal(getItem otherMod, (itemFromID limitModules[depth-1]))) continue
        othero = source l
        if (null othero) {
            load(otherVersion,false)
        }
        othero = source l
        if (null othero) continue
        if (isDeleted othero) continue
        doneOne = true
        if (depth == 1) {
                
                 s = name(otherMod)
                if (isBaseline(otherVersion)) {
                    s = s " [" versionString(otherVersion) "]"
                }
                disp = disp s
                if (exists attribute "Release Number")
 
                s = probeRichAttr_(othero,"Release Number", true)
                if (parent obj != null)
                {PO = parent  othero
                s = PO."Release Number"
                disp = disp "-" s
                displayRich("\\pard " disp)
            }
        }
    }
}
showIn(obj,1)

dnmel0 - Mon Mar 12 02:21:16 EDT 2012

Re: Check if attribute exists if so bring back parent object information
llandale - Mon Mar 12 15:47:41 EDT 2012

I'm in a hurry so I'll scribble. The "if exists attribute" line should fail since you don't know which module is currently "current". Perhaps you want to display the value if it has one, figuring if the attribute doesn't exist then it has no value.

The reason you get so much info is because you are displaying the full name of that other module and the Release Number of "othero", as well as the release number of its parent.
 

//     s = name(otherMod)
//                if (isBaseline(otherVersion)) {
//                s = s " [" versionString(otherVersion) "]"
//                }
//                disp = disp s
//                if (exists attribute "Release Number")
 
//                s = probeRichAttr_(othero,"Release Number", true)
//                if (parent obj != null)
//                s = PO."Release Number"
                disp = disp "-" s
                displayRich("\\pard " disp)
    PO = parent  othero
    if (!null PO) //
    then s = probeAttr_(PO."Release Number")    //<<-- returns "" if there is no such attr
    else s = ""
    if (!null s) then displayRich("\\pard " s)


-Louie

Re: Check if attribute exists if so bring back parent object information
dnmel0 - Mon Mar 12 23:35:38 EDT 2012

Thanks Louie, I added your code and it reported the following errors:

-E- DXL: <Line:57> incorrect arguments for (if)
-E- DXL: <Line:58> incorrect arguments for function (probeAttr_)
-I- DXL: all done with 2 errors and 0 warnings

Also I was wanting to add the name of the other module in front of the release number, if possible?

Thanks,
Dan

Re: Check if attribute exists if so bring back parent object information
llandale - Tue Mar 13 13:37:34 EDT 2012

dnmel0 - Mon Mar 12 23:35:38 EDT 2012
Thanks Louie, I added your code and it reported the following errors:

-E- DXL: <Line:57> incorrect arguments for (if)
-E- DXL: <Line:58> incorrect arguments for function (probeAttr_)
-I- DXL: all done with 2 errors and 0 warnings

Also I was wanting to add the name of the other module in front of the release number, if possible?

Thanks,
Dan

You want it to work? Sheesh. :)

Needed a comma not period in probeAttr_. Maybe this works:

//                disp = disp "-" s   // forgot to comment these out originally
//                displayRich("\\pard " disp)
    PO = parent  othero
    if (!null PO) //
    then s = probeAttr_(PO, "Release Number")    //<<-- returns "" if there is no such attr
    else s = ""
    if (!null s) 
    { string Name = name(otherMod)
      if (isBaseline(otherVersion)) {
            Name = Name " [" versionString(otherVersion) "]"
      }
   Option1:
      display(Name)
      displayRich("\\pard " s)      // on separate lines
   Option2:
      displayRich("\\pard " Name ":  " s)   // on one line.
 
    }

Re: Check if attribute exists if so bring back parent object information
dnmel0 - Tue Mar 13 19:08:01 EDT 2012

Thanks Louie, works exactly how it needs to.

Cheers,
Dan.